package com.vvlive.caibao.smartcity.ui;

import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import android.widget.TextView;

import com.vvlive.caibao.smartcity.base.BaseActivity;
import com.vvlive.caibao.smartcity.utils.SettingsUtil;
import com.vvlive.caibao.smartcity.view.CommonActionBar;

import org.kymjs.kjframe.ui.BindView;

import smartcity.vvlive.caibao.com.smartc.R;

/**
 * Created by zhj on 2015/7/16.
 * 隐私设置
 */
public class PrivateSettingsActivity extends BaseActivity implements OnCheckedChangeListener{

    @BindView(id = R.id.switch_push_setting)
    private Switch mPushSwitch;  // 是否自动推送
    @BindView(id = R.id.switch_lock_setting)
    private Switch mLockSwitch;  // 是否自动定位
    @BindView(id = R.id.clear_data_settings, click = true)
    private Button mClearData;   // 清除数据
    @BindView(id = R.id.test_edit_meeting_ip, click = true)
    private Button mTestEditIP;

    @Override
    protected int getContentViewRes() {
        return R.layout.activity_private_settings;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        CommonActionBar actionBar = super.getCommonActionBar();
        actionBar.setTitle("隐私设置");
        actionBar.setMoreVisible(false);

        mPushSwitch.setOnCheckedChangeListener(this);
        mLockSwitch.setOnCheckedChangeListener(this);
    }

    @Override
    public void widgetClick(View v) {
        super.widgetClick(v);
        int id = v.getId();
        switch (id){
            case R.id.clear_data_settings:
                confirm("真的要清除所有数据？", new OnConfirmListener() {
                    @Override
                    public void onConfirm(boolean isConfirmed) {
                        toast(isConfirmed ? "清除数据！" : "取消清除数据。");
                    }
                });
                break;
            case R.id.test_edit_meeting_ip: // 修改会议室ip
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                View view = getLayoutInflater().inflate(R.layout.dialog_test_edit_ip, null);

                builder.setView(view);
                AlertDialog dialog = builder.create();
                final TextView text = (TextView) view.findViewById(R.id.dialog_ip_input);
                Button submit = (Button) view.findViewById(R.id.dialog_ip_submit);
                submit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String newIp = text.getText().toString();
                        SettingsUtil util = new SettingsUtil(PrivateSettingsActivity.this);
                        if(!TextUtils.isEmpty(newIp)) {
                           util.editMeetingIP(newIp);
                        }else{
                           toast("请输入IP");
                        }
                    }
                });
                dialog.show();
                break;
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()){
            case R.id.switch_push_setting:
                toast(isChecked ? "开启推送" : "关闭推送");
                break;
            case R.id.switch_lock_setting:
                toast(isChecked ? "开启定位" : "关闭定位");
                break;
        }
    }
}
